package com.playball.lottery.nt.animal;

import com.playball.lottery.nt.GetJsonData;
import com.playball.lottery.util.ConvertJsonToList;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.Map;

/**
 * Created by Administrator on 2017/3/15.
 */

public class BaseServiceImpl2 {

    public static String prefixUrl = GetJsonData.urlPath + "?";
    public static String rechargeUrl="http://weixin.tcaio2o.com/Recharge/AppCharge?";

    /**
     * 拼接基本的参数URL字符串

     * @param platformVersion
     * @param UserID
     * @param platformCode
     * @param sign
     * @param appVersion
     * @param cmdName
     * @param uuid
     * @param action
     * @return
     */
    public String getURLOfBasic(
            String platformVersion,
            String UserID,
            String platformCode,
            String sign,
            String appVersion,
            String cmdName,
            String uuid,
            String action
         ){
        String result;
        Map<String, Object> mapParams = ConvertJsonToList.getMap(
                this.getJSONOfBasic(platformVersion,UserID,platformCode, sign, appVersion,cmdName,
                        uuid,action));
        // 拼接参数
        StringBuffer sb = new StringBuffer();
        for (Map.Entry<String, Object> entry : mapParams.entrySet()) {
            sb.append(entry.getKey()).append("=").append(entry.getValue().toString());
            sb.append("&");
        }
        result = sb.deleteCharAt(sb.length() - 1).toString();
        return result;
    }


    /**
     * 拼接基本的参数JSON字符串
     * @param platformVersion
     * @param UserID
     * @param platformCode
     * @param sign
     * @param appVersion
     * @param cmdName
     * @param uuid
     * @param action
     * @return
     */
    public String getJSONOfBasic(
          String platformVersion,  String UserID, String platformCode, String sign, String appVersion,String cmdName, String uuid,
            String action){
        String result;
        JSONObject params = new JSONObject();
        try {
            params.put("platformVersion", platformVersion);
            params.put("UserID", UserID);
            params.put("platformCode", platformCode);
            params.put("sign", sign);
            params.put("appVersion", appVersion);
            params.put("cmdName", cmdName);
            params.put("uuid", uuid);
            params.put("action", action);

        } catch (JSONException e) {
            e.printStackTrace();
        }
        result = params.toString();
        return result;
    }
    /**
     * 获取参数的URL
     * @param paramsJSON
     * @return
     */
    public String getURLOfParams(String paramsJSON){
        String result = "params=";
        if (paramsJSON == null || paramsJSON.trim().length() == 0){
            result += "{}";
        } else {
            result += paramsJSON;
        }
        return result;
    }

}
